package org.timemachine.factory;

import java.lang.reflect.Field;
import java.util.Date;

import org.timemachine.context.TMThreadLocal;
import org.timemachine.model.base.ForwardChangeInfo;

public class ForwardChangeInfoFactory {

	public static ForwardChangeInfo getNewInstance() {
		ForwardChangeInfo changeInfo = new ForwardChangeInfo();
		changeInfo.setCreateTimeStamp(new Date());
		changeInfo.setChangeTimeStamp(TMThreadLocal.getContext().getChangeTimeStamp());
		

		Class<?> c = changeInfo.getClass();
		try {
			for (String key : TMThreadLocal.getContext().getKeySet()) {

				Field chap = c.getDeclaredField(key);
				chap.setAccessible(true);

				chap.set(changeInfo, TMThreadLocal.getContext().get(key));

			}
		} catch (Exception e) {
			// TODO nothing to do
		}

		return changeInfo;
	}

	

}
